package com.monkey.redis.init;

import com.monkey.redis.util.SpringContextUtil;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 该类是在项目启动的时候调用所有需要缓存的方法 进行预热缓存
 */
@Component
public class InitCache implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        ApplicationContext applicationContext = SpringContextUtil.getApplicationContext();
        Map<String, AbstractCache> beanMap = applicationContext.getBeansOfType(AbstractCache.class);
        if(beanMap==null){
            return;
        }
        for (AbstractCache value : beanMap.values()) {
            AbstractCache bean = (AbstractCache)SpringContextUtil.getBean(value.getClass());
            //bean.initCache();
        }
    }
}
